#!/bin/bash
echo "===================================================="
echo "deploy frontend start"
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
cd "$SCRIPT_DIR"

ROOT_DIR=$(dirname $(dirname "$SCRIPT_DIR"))
PLUGIN_DIR=$ROOT_DIR/plugins
FRONTEND_DIR=$ROOT_DIR/wex-frontend

if [ ! -d "$PLUGIN_DIR" ]; then
  mkdir -p "$PLUGIN_DIR"
fi

# 整合扩展到项目中
echo "start add plugins..."
for plugin_dir in $(ls -d $PLUGIN_DIR); do
    if [ -d "$plugin_dir/frontend" ]; then
        plugin_name=$(basename $plugin_dir)
        target_dir="$FRONTEND_DIR/plugin/plugins/$plugin_name"
        mkdir -p "$target_dir"
        cp -r "$plugin_dir/frontend/"* "$target_dir"
        echo "Moved plugin $plugin_name to $target_dir"
    fi
done
echo "add plugins done"

cd "$FRONTEND_DIR"
pnpm install
pnpm build
echo "done"
echo "deploy frontend done"
echo "===================================================="
